<?php

use yii\db\Migration;

class m000000_000015_create_upload_file extends Migration
{
    public function up()
    {
        $this->createTable('{{%upload_file}}', [
            'id'=>$this->primaryKey(), // PK
            'uid'=>$this->integer(), // 用户编号
            'time'=>$this->integer(), // 上传时间
            'type'=>$this->integer(), // 类型
            'status'=>$this->integer(), // 状态
            'url'=>$this->string(512), // 保存路径
        ]);
        $this->createIndex('fk_upload_file_user1_idx', '{{%upload_file}}', ['uid']);
        try {
            $this->addForeignKey('fk_upload_file_user1', '{{%upload_file}}', ['uid'], '{{%user}}', ['id']);
        } catch (Exception $e) {
        }
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['upload_file_status', 1, '正常'],
            ['upload_file_status', 0, '删除'],
        ]);
    }

    public function down()
    {
        $this->delete('{{%key_map}}', ['t'=>'upload_file_status']);
        $this->dropTable('{{%upload_file}}');
    }
}
